package Gather.ExerciseDome;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Random;

/**
 * ClassName:Exercise001
 * Package:Gather.ExerciseDome
 * Description:
 *
 * @Author:ZhangXin
 * @Create2023/2/21-20:22
 * @Version:v1.0
 */
public class Exercise001 {
    /*班级里有N个学生,实现随机点名器*/
    public static void main(String[] args) {
        //定义集合
        ArrayList<String> list = new ArrayList<>();
        //添加数据
        Collections.addAll(list,"张鑫","郭永杰","梁二永","贾文玉","孙建明","郭佳伟","孙伟晔");
        //随机点名
        Random r = new Random();
        int index = r.nextInt(list.size());
        System.out.println(list.get(index));

        //打乱集合中的数据
        Collections.shuffle(list);
        String name = list.get(0);
        System.out.println(name);
    }
}
